

void tc1_lvaure_or_rvalue()
{
	//i and j are the same type, no conversion happens, so ternary operator produces a lvalue. 
	int i, j;
	(true ? i : j) = 1;
	(false ? i : j) = 2;

	short s;
	//(true ? i : s) = 1;	//won't compile, convert happens, ternary operator produces a rvalue;

	auto res = true ? '0' : 0;	// the common type is int, so '0' is converted to int, res = 48 (ascii code of '0').

	i = 1; j = 1;
	res = true ? ++i : ++j;		//j won't be increased, same effect as if-else;
}


/*
template<typename T, typename U>
struct common_type
{
	typedef decltype(true ? std::declval<T>() : std::declval<U>()) type;
};

template<typename T, typename U>
struct is_same{ auto static const value = false; };
template<typename T>
struct is_same<T, T>{ auto static const value = true; };

void tc2_common_type()
{
	auto same = is_same<int, common_type<int, short>::type>::value;
}

*/

int Test_TernaryOperator(int, char**)
{
	tc1_lvaure_or_rvalue();
	//void tc2_common_type();
	return 0;
}